package pt.mauromad.guias.controller;

import static java.lang.String.format;
import static pt.mauromad.guias.utils.transformation.Transformations.Address2Dao;
import static pt.mauromad.guias.utils.transformation.Transformations.Company2Dao;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import pt.mauromad.guias.bean.CompanyBean;
import pt.mauromad.guias.dao.AddressDao;
import pt.mauromad.guias.dao.CompanyDao;
import pt.mauromad.guias.utils.form.Action;

@Controller
@RequestMapping("/company")
public class CompanyController extends BaseController {
//	@RequestMapping(value = "/all")
//	public String all(Model model) {
//		model.addAttribute("companies", companyService.getByAccount(getAccount().getId()));
//		return "list/all-companies";
//	}
//
//	@RequestMapping(value = "/new", method = RequestMethod.GET)
//	public String create(Model model) {
//		model.addAttribute("editable", true);
//		add(model, Action.createPost("save"));
//		return "company-form";
//	}
//
//	@RequestMapping(value = "/new", method = RequestMethod.POST, params = "action=save")
//	public String createCompany(Model model, @Validated CompanyBean bean) {
//		CompanyDao company = Company2Dao.get(bean);
//		company.setAccount(getAccount());
//		companyService.save(company);
//
//		AddressDao address = Address2Dao.get(bean.getAddress());
//		address.setCompany(company);
//		addressService.save(address);
//
//		company.setMainAddress(address);
//		companyService.save(company);
//
//		return format("redirect:/company/%s", company.getId());
//	}
//
//	@RequestMapping(value = "/{company:[0-9]+}", method = RequestMethod.GET)
//	public String view(Model model, @PathVariable CompanyDao company) {
//		model.addAttribute("company", company);
//		add(model, Action.createPost("manage"));
//		add(model, Action.createPost(company.isEnabled() ? "disable" : "enable"));
//		add(model, Action.createPost("new.address"));
//
//		return "company-form";
//	}
//
//	@RequestMapping(value = "/{company:[0-9]+}", method = RequestMethod.POST, params = "action=manage")
//	public String manage(Model model, @PathVariable CompanyDao company) {
//		model.addAttribute("company", company);
//		model.addAttribute("editable", true);
//		add(model, Action.createPost("manage.save"));
//		return "company-form";
//	}
//
//	@RequestMapping(value = "/{company:[0-9]+}", method = RequestMethod.POST, params = "action=manage.save")
//	public String manageSave(Model model, @Validated CompanyBean bean, @PathVariable Long company) {
//		bean.setId(company);
//		companyService.save(Company2Dao.get(bean));
//		return format("redirect:/company/%s", company);
//	}
//
//	@RequestMapping(value = "/{company:[0-9]+}", method = RequestMethod.POST, params = "action=disable")
//	public String disable(Model model, @PathVariable CompanyDao company) {
//		company.setEnabled(false);
//		companyService.save(company);
//		return format("redirect:/company/%s", company.getId());
//	}
//
//	@RequestMapping(value = "/{company:[0-9]+}", method = RequestMethod.POST, params = "action=enable")
//	public String enable(Model model, @PathVariable CompanyDao company) {
//		company.setEnabled(true);
//		companyService.save(company);
//		return format("redirect:/company/%s", company.getId());
//	}
}
